package net.niufei.study.cpatterns.activeobject;


public class FutureResult implements Result {
	private boolean completed = false;
	private Result result;
	
	
	@Override
	public synchronized Object getResultValue() {
		try {
			while (!completed) {
				wait();
			}
		} catch (InterruptedException e) {
		}
		return result == null ? null : result.getResultValue();
	}

	
	public synchronized void setResult(Result result) {
		if(completed)
			return;
		
		this.result = result;
		completed = true;
		notifyAll();
	}
}
